import os
import pygame
from random import *


# 获取当前项目的路径
projectPath=os.path.abspath('..')


# 敌方小型号飞机
class SmallEnemyPlane(pygame.sprite.Sprite):

    def __init__(self, bg_size):
        self.image = pygame.image.load(projectPath + "/resources/images/enemy1.png").convert_alpha()
        self.destroyImages = []
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy1_down1.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy1_down2.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy1_down3.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy1_down4.png").convert_alpha())
        self.speed = 1
        self.active = True
        self.mask = pygame.mask.from_surface(self.image)
        self.width = bg_size[0]
        self.height = bg_size[1]
        self.rect = self.image.get_rect()
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.top = randint(-self.height, 0)



    # 敌方飞机只会向下移动
    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    # 重新初始化敌方飞机
    def reset(self):
        self.active = True
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.top = randint(-self.height, 0)

# 敌方中型号飞机
class MediumEnemyPlane(pygame.sprite.Sprite):
    # 类的全局变量，飞机的生命值
    energy = 8

    def __init__(self, bg_size):
        self.image = pygame.image.load(projectPath + "/resources/images/enemy2.png").convert_alpha()

        self.destroyImages = []
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy2_down1.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy2_down2.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy2_down3.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy2_down4.png").convert_alpha())

        self.imageHit=pygame.image.load(projectPath + "/resources/images/enemy2_hit.png").convert_alpha()
        self.hit = False

        self.speed = 1
        self.active = True
        self.mask = pygame.mask.from_surface(self.image)
        self.width = bg_size[0]
        self.height = bg_size[1]
        self.rect = self.image.get_rect()
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.top = randint(-2 * self.height, -self.height)
        self.energy=MediumEnemyPlane.energy

    # 敌方飞机只会向下移动
    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    # 重新初始化敌方飞机
    def reset(self):
        self.active = True
        self.energy = MediumEnemyPlane.energy
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.top = randint(-2* self.height, -self.height)



# 敌方大型号飞机
class BigEnemyPlane(pygame.sprite.Sprite):
    # 类的全局变量，飞机的生命值
    energy = 15

    def __init__(self, bg_size):

        self.image1= pygame.image.load(projectPath + "/resources/images/enemy3_n1.png").convert_alpha()
        self.image2= pygame.image.load(projectPath + "/resources/images/enemy3_n2.png").convert_alpha()

        self.destroyImages = []
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy3_down1.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy3_down2.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy3_down3.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy3_down4.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy3_down5.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath + "/resources/images/enemy3_down6.png").convert_alpha())

        self.imageHit=pygame.image.load(projectPath + "/resources/images/enemy3_hit.png").convert_alpha()
        self.hit = False

        self.speed =1
        self.active = True
        self.mask = pygame.mask.from_surface(self.image1)
        self.width = bg_size[0]
        self.height = bg_size[1]
        self.rect = self.image1.get_rect()
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.top = randint(-3* self.height, -2*self.height)
        self.energy=BigEnemyPlane.energy

    # 敌方飞机只会向下移动
    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

    # 重新初始化敌方飞机
    def reset(self):
        self.active = True
        self.energy = BigEnemyPlane.energy
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.top = randint(-3 * self.height, -2*self.height)

